<template>
  <div :class="{ 'navbar-com': true, expand: menuStore.expandFold }">
    <!-- <div class="navbar-left">
      <div class="navbar-left-top">
        <div class="expand-fold" @click="changeExpand">
          <el-icon class="expand-fold-icon" v-if="menuStore.expandFold">
            <Expand />
          </el-icon>
          <el-icon class="expand-fold-icon" v-if="!menuStore.expandFold">
            <Fold />
          </el-icon>
        </div>
      </div>
      <div class="navbar-left-bottom">
        <div class="return-refresh-home">
          <div class="icon-item" @click="returnFun">
            <el-icon class="icon">
              <ArrowLeft />
            </el-icon>
          </div>
          <div class="icon-item" @click="refreshFun">
            <el-icon class="icon">
              <RefreshRight />
            </el-icon>
          </div>
          <div class="icon-item" @click="HomeFun">
            <el-icon class="icon">
              <House />
            </el-icon>
          </div>
        </div>
      </div>
    </div> -->
    <el-dropdown class="el-dropdown-box">
      <span class="el-dropdown-link" v-if="userStore.userInfo">
        <span class="username">{{ userStore.userInfo.username }}</span>
        <span :class="'role ' + userStore.userInfo.role.code">{{ userStore.userInfo.role.name }}</span>
        <el-icon class="el-icon--right">
          <arrow-down />
        </el-icon>
      </span>
      <template #dropdown>
        <el-dropdown-menu style="width: 200px">
          <el-dropdown-item :icon="Plus" @click="goMe">个人中心</el-dropdown-item>
          <el-dropdown-item :icon="Plus" @click="logout">退出</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
    <div v-if="!userStore.userInfo"><el-button type="danger" style="width: 100px" @click="goLogin">去登录</el-button></div>
    <!-- <div class="words-timeOut" v-if="userStore.userInfo">
      <div class="words">tokens: {{ userStore.userInfo.words }}</div>
      <div class="words">vip: {{ userStore.userInfo.timeOut }}天</div>
    </div> -->
  </div>
  <div class="navbar-mobile-com">手机导航栏</div>
</template>
<script setup>
import { onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/pinia/user'
import { useMenuStore } from '@/pinia/menu'
import { setRem } from '@/utils/rem.js'
import { indexRoute } from '@/router'

const userStore = useUserStore()
const menuStore = useMenuStore()

// const menu = JSON.parse(JSON.stringify(menuStore.menus))

const router = useRouter()

// 退出登录
const logout = () => {
  userStore.logout()
  router.push({ path: '/login' })
}

// 返回
const returnFun = () => {
  router.go(-1)
}

// 刷新
const refreshFun = () => {
  router.go(0)
}

// 主页
const HomeFun = () => {
  router.push({ path: indexRoute })
}

// 展开折叠
const changeExpand = () => {
  menuStore.expandFoldAct()
}

// 登陆
const goLogin = () => {
  router.push({ path: '/home/login' })
}

const goMe = () => {
  router.push({ path: '/home/me' })
}

onMounted(() => {
  setRem()
})
</script>
<style lang="scss">
.navbar-com {
  width: 200px;
  position: fixed;
  left: 0;
  // top: 0;
  // right: 0;
  bottom: 20px;
  z-index: 99999;
  // padding-right: 15px;
  box-sizing: border-box;
  // height: 60px;
  line-height: 60px;
  background-color: #fff;
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  // box-shadow: 0 1px 5px 0 rgb(48 49 51 / 15%), 0 0 1px 0 rgb(48 49 51 / 24%);
  transition: all 0.5s;
  background: none;

  .words-timeOut {
    width: 124px;
    line-height: 30px;
  }

  .navbar-left {
    flex-grow: 1;

    .navbar-left-top {
      height: 30px;
      line-height: 30px;
      padding-left: 15px;
      @include flex();

      .expand-fold {
        @include flex();
        height: 30px;
        cursor: pointer;

        .expand-fold-icon {
          color: #636564;
          font-size: 20px;
        }
      }
    }

    .navbar-left-bottom {
      width: 100%;
      height: 30px;
      line-height: 30px;
      @include flex();

      .return-refresh-home {
        @include flex();

        .icon-item {
          height: 30px;
          width: 30px;
          box-sizing: border-box;
          border-top: 1px solid #ededed;
          border-right: 1px solid #ededed;
          font-size: 16px;
          color: #9d9d9d;
          cursor: pointer;
          @include flex(row, center, center);
        }
      }

      .tab-box {
        height: 30px;
        padding-right: 15px;
        box-sizing: border-box;
        flex-grow: 1;
        @include flex();

        .tab-item {
          width: 90px;
          height: 30px;
          border-top: 2px solid #fff;
          color: #7f8180;
          font-size: 12px;
          box-sizing: border-box;
          @include flex(row, center, center);
          cursor: pointer;

          .name {
            width: 60px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          }

          .icon {
            color: #a7a7a7;
            margin-left: 5px;
          }
        }

        .tab-item.active {
          border-top: 2px solid #202221;
          color: #252726;
          background-color: #f5f5f5;
        }
      }
    }
  }
}

.navbar-com.expand {
  left: 63px;
}
</style>
<style lang="scss">
.el-dropdown-box {
  cursor: pointer;
  height: 50px;
  line-height: 50px;
  color: #fff;

  .el-icon {
    display: none;
  }
}

.role {
  padding: 3px 5px;
  font-size: 12px;
  margin-right: 5px;
  margin-left: 10px;
}

.role.youke {
  background-color: #efefef;
  color: #333;
}

.role.vip4,
.role.vip3,
.role.vip1,
.role.vip2 {
  color: #ff5b5b;
  background-color: rgba(255, 91, 91, 0.18);
}
</style>
